package cn.yunhe.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class TomcatServer {
	/**
	 * @param args112
	 * 
	 *            tomcatserver一有客户端上来就监听
	 * @throws IOException
	 */
	public static void main(String[] args) {
		
		//从配置文件读取KEY端口号到变量
		int port = Integer.parseInt((String) WebProperties.getInstance().get("port"));
		
		ServerSocket tomcat = null;
		
		try {
			tomcat = new ServerSocket(port);
		} catch (IOException e) {

			Utils.printException(e);
		}
		System.out.println(Utils.formatDate() + "\t服务器启动,监听" + tomcat.getLocalPort() + "端口");
		
		while (true) {
			Socket s = null;
			try {
				s = tomcat.accept();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				Utils.printException(e);
			}
			System.out.println("客户端" + s.getRemoteSocketAddress() + "登陆上了服务器");
			// 这是一个连接会话任务类，实现Runnable接口，网络操作需要启用线程
			// 在会话任务类中
			HttpSessionTask hst = new HttpSessionTask(s);
			new Thread(hst).start();
		}

	}
}